-
Notifications
You must be signed in to change notification settings - Fork 62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Start with python match
statement
#1801
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files
☔ View full report in Codecov by Sentry. |
...anguage-python/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/python/ExpressionHandler.kt
Outdated
Show resolved
Hide resolved
...anguage-python/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/python/ExpressionHandler.kt
Outdated
Show resolved
Hide resolved
cpg-language-python/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/python/Python.kt
Show resolved
Hide resolved
...language-python/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/python/StatementHandler.kt
Outdated
Show resolved
Hide resolved
...est/kotlin/de/fraunhofer/aisec/cpg/frontends/python/statementHandler/StatementHandlerTest.kt
Outdated
Show resolved
Hide resolved
...anguage-python/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/python/ExpressionHandler.kt
Show resolved
Hide resolved
...anguage-python/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/python/ExpressionHandler.kt
Outdated
Show resolved
Hide resolved
...anguage-python/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/python/ExpressionHandler.kt
Outdated
Show resolved
Hide resolved
...language-python/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/python/StatementHandler.kt
Outdated
Show resolved
Hide resolved
...language-python/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/python/StatementHandler.kt
Outdated
Show resolved
Hide resolved
...language-python/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/python/StatementHandler.kt
Outdated
Show resolved
Hide resolved
...est/kotlin/de/fraunhofer/aisec/cpg/frontends/python/statementHandler/StatementHandlerTest.kt
Outdated
Show resolved
Hide resolved
...language-python/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/python/StatementHandler.kt
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, I like this very much.
Some more nitpicking comments, but I think this is good to be merged :)
We should open an issue to track the not implemented cases...
...language-python/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/python/StatementHandler.kt
Outdated
Show resolved
Hide resolved
...language-python/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/python/StatementHandler.kt
Show resolved
Hide resolved
* [Python.AST.match_case.body]. | ||
* | ||
* The [CaseStatement] is generated by the [Python.AST.match_case.pattern] and, if available, | ||
* [Python.AST.match_case.guard]. If there's a `guard` present, we model the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"If there's a guard
present, we model the... " this is a bit confusing. There is also a CaseStmt if there is no guard, isn't there?
...language-python/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/python/StatementHandler.kt
Outdated
Show resolved
Hide resolved
...language-python/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/python/StatementHandler.kt
Outdated
Show resolved
Hide resolved
} else { | ||
newCaseStatement(rawNode = node).apply { | ||
this.caseExpression = | ||
node.guard?.let { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like this style. I think a simple if / else if / else at the top level would be easier to read.
newBinaryOperator(operatorCode = "===", rawNode = node).implicit().apply { | ||
this.lhs = newReference(name = subject) | ||
this.rhs = | ||
when (val value = node.value) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It feels like this should be an extra function (at least if we use this logic somewhere else, too). Have you seen easyConstant
in the ExpressionHandler?.
We only expect True
, False
or None
here according to the doc.
} | ||
|
||
@Test | ||
fun testMatchAnd() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
testMatchGuard?
…ontends/python/StatementHandler.kt Co-authored-by: Maximilian Kaul <[email protected]>
Co-authored-by: Maximilian Kaul <[email protected]>
This PR adds the basic comparisons which can be found in python's
match
statement. The statement is modeled as aSwitchStatement
and the main issue are theCaseStatements
which offer a wide range of checks, some of which we cannot model trivially.